//
//  ViewController.m
//  03.图片浏览器
//
//  Created by 张青花 on 15/7/20.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
/**
 上标签
 */
@property (weak, nonatomic) IBOutlet UILabel *toplabel;

/**
 照片
 */
@property (weak, nonatomic) IBOutlet UIImageView *photoImageView;

/**
  索引
 */
@property (assign,nonatomic) int index;


@property (weak, nonatomic) IBOutlet UIButton *leftBtn;

@property (weak, nonatomic) IBOutlet UIButton *rightBtn;

/**
 下标签
 */
@property (weak, nonatomic) IBOutlet UILabel *downlabel;


@property (strong,nonatomic) NSArray *array;
@end



@implementation ViewController


- (NSArray*)array
{
    if (_array ==nil) {
//        _array =@[@{@"ico":@"biaoqingdi",@"desc":@"1号小胆子"},
//                  @{@"ico":@"bingli",@"desc":@"2号小胆子"},
//                  @{@"ico":@"chiniupa",@"desc":@"3号小胆子"},
//                  @{@"ico":@"danteng",@"desc":@"4号小胆子"},
//                  @{@"ico":@"wangba",@"desc":@"5号小胆子"}];
        
        NSString *path1 = [[NSBundle mainBundle] pathForResource:@"imageData" ofType:@"plist"];

        
//        NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES).firstObject;
//        
//        NSLog(@"%@",path);
//   
//        NSString *filename=[path stringByAppendingPathComponent:@"imageData.plist"];
//        
//        NSLog(@"filename = %@",filename);
        NSLog(@"path1 = %@",path1);
        _array = [NSArray arrayWithContentsOfFile:path1];
    }
    return _array;
}

- (void) viewDidLoad
{
    [super viewDidLoad];
//    self.toplabel.text =@"1/5";
//    self.photoImageView.image = [UIImage imageNamed:@"biaoqingdi"];
//    self.downlabel.text =@"操蛋1号小胆子";
    
    
    
    
    [self change];
}


- (void)change
{
    self.toplabel.text = [NSString stringWithFormat:@"%d/%d",self.index+1,self.array.count];
   
    
    NSDictionary *dic = self.array[self.index];
    
    self.photoImageView.image = [UIImage imageNamed:dic[@"icon"]];
    
    self.downlabel.text = dic[@"desc"];
    
    if (self.index==0) {
        self.leftBtn.enabled = NO;
    }
    else{
        self.leftBtn.enabled = YES;
    }
    
    if (self.index==(self.array.count-1)) {
        self.rightBtn.enabled = NO;
    }
    else{
        self.rightBtn.enabled = YES;
    }

}


- (IBAction)leftGo {
    self.index--;
    [self change];
    
    
}

- (IBAction)rightGo {
    self.index++;
    [self change];
}

@end
